
/*
 * BinaryTreeBasis.java
  */
// Original code found in "Data Abstraction & Problem Soving with Java"
// 2005., Carrano, F., Prichard, J.;

public abstract class BinaryTreeBasis<T>
{
    protected TreeNode<T> root;

    //*************************************************************
    /** Creates a new instance of BinaryTreeBasis */
    public BinaryTreeBasis()
    {
        root = null;
    }

    //*************************************************************
    public BinaryTreeBasis(T rootItem)
    {
        root = new TreeNode<T>(rootItem, null, null);
    }

    //*************************************************************
    public boolean isEmpty()
    {
        return root == null;
    }

    //*************************************************************
    public void makeEmpty()
    {
        root = null;
    }

    //*************************************************************
    public T getRootItem() throws TreeException
    {
        if (root == null)
        {
            throw new TreeException("TreeException: Empty tree");
        }
        else
        {
            return root.getItem();
        }
    }

    //*************************************************************
    public abstract void setRootItem(T newItem);
        // Throws UnsupportedOperationException if operation
        // is not supported.
} // end BinaryTreeBasis